﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using QuocTeViet.DO;
using QuocTeViet.BL;

namespace QuocTeViet.AdminCP.PageUC
{
    public partial class ucProductUnit : System.Web.UI.UserControl
    {
        cmsDonViDO objDonVi = new cmsDonViDO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ProductUnitID"] != null)
            {
                objDonVi.DonViID = int.Parse(Request.QueryString["ProductUnitID"].ToString());
                InitForm();
            }
        }

        protected void InitForm()
        {
            objDonVi = new cmsDonViBL().Select(objDonVi);
             txtTenNhanHieu.Text = objDonVi.DonViTinh.ToString();
             TextBox1.Text = objDonVi.eDonViTinh;
            if (!string.IsNullOrEmpty(Convert.ToString(objDonVi.MoTa)))
            {
                txtMoTa.Text = objDonVi.MoTa.ToString();
            }
            try
            {
                //   drpParentID.SelectedValue = objLSanPham.ParentID.ToString();
            }
            catch
            {
            }
        }

        protected void SetObject()
        {
            objDonVi.DonViTinh = txtTenNhanHieu.Text;
            objDonVi.MoTa = txtMoTa.Text;
            objDonVi.eDonViTinh = TextBox1.Text;
        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {

        }
        long i;
        protected void btnLuu_Click(object sender, EventArgs e)
        {
            SetObject();
            if (objDonVi.DonViID <= 0)
            {
                i = new cmsDonViBL().Insert(objDonVi);
                Functions.Alert("Thêm mới thành công", "Default.aspx?Page=ListProductUnit");
            }
            else
            {
                i = new cmsDonViBL().Update(objDonVi);
                //    i = objDonVi.NhanHieuID;
                Functions.Alert("Cập nhật thành công", "Default.aspx?Page=ListProductUnit");
            }
        }
    }
}